//
//  RYDingdanDetailView.swift
//  SheYangBigData
//
//  Created by 宋海胜 on 2021/1/14.
//  Copyright © 2021 叁拾叁. All rights reserved.
//

import UIKit


class RYDingdanDetailCell: SYBaseCell , UITableViewDelegate, UITableViewDataSource {
    
    var tableView: UITableView!
    var model:  RYDingdanModel!

    var bgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor(hex: 0x367FF6)
        v.layer.cornerRadius = 2
        return v
    }()
    
    var sepView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = Constant.bgViewColor
        return v
    }()
    
    let nameLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1E1E1E)
        v.font = 17.autoBoldFontSize()
        v.text = "订单信息"
        return v
    }()
    
    

    func configure(_ model: RYDingdanModel) {
        self.model = model
        tableView.reloadData()
    }
    
    override func initViews() {
        
        
        setTableView()
        contentView.addSubview(nameLb)
        contentView.addSubview(bgView)
        contentView.addSubview(tableView)
        
        contentView.addSubview(sepView)
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(16.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(14.5))
            make.width.equalTo(4.0.autoWidth())
            make.height.equalTo(15.0.autoWidth())
        }
        nameLb.snp.makeConstraints { (make) in
            make.centerY.equalTo(bgView)
            make.left.equalTo(bgView.snp.right).offset(autoWidth(7.0))
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(16.0.autoWidth())
        }
        tableView.snp.makeConstraints { (make) in
            make.top.equalTo(nameLb.snp.bottom).offset(autoWidth(10.0))
            make.left.right.equalToSuperview()
            make.height.equalTo(100.0.autoWidth())
        }
        
        sepView.snp.makeConstraints { (make) in
            make.top.equalTo(tableView.snp.bottom).offset(10.0.autoWidth())
            make.left.right.equalToSuperview()
            make.height.equalTo(10.0.autoWidth())
            make.bottom.equalToSuperview()
        }
    }
    
    func setTableView() {
        
        //创建表格视图
        self.tableView = UITableView(frame: CGRect(x: 0, y: NAV_HEIGHT, width: SCREEN_WIDTH, height: SCREEN_HEIGHT-NAV_HEIGHT-BOTTOM_SAFE_HEIGHT), style:.plain)
        self.tableView.separatorStyle = .none
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.isScrollEnabled = false
        self.tableView!.register(RYDingdanDetailSubCell.self, forCellReuseIdentifier: "Cell")
        self.contentView.addSubview(self.tableView!)
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: RYDingdanDetailSubCell? = tableView.dequeueReusableCell(withIdentifier: "Cell") as? RYDingdanDetailSubCell
        cell?.selectionStyle = .none
        if nil != self.model {
            switch indexPath.row {
            case 0:
                cell?.nameLb.text = "订单编号"
                cell?.contentLb.text = model.orderNumber
            case 1:
                cell?.nameLb.text = "下单时间"
                cell?.contentLb.text = model.orderTime
            case 2:
                cell?.nameLb.text = "订单总价"
                cell?.contentLb.text = String(format: "%.2f", model.orderPrice ?? 0)
            case 3:
                cell?.nameLb.text = "支付方式"
                cell?.contentLb.text = model.getZhifufangshi()
            case 4:
                cell?.nameLb.text = "用户留言"
                cell?.contentLb.text = model.remarks
                
            default:
                break
            }
        }
        return cell!
    }
   
}
